<?php
$loan_model = $this->loanalldata;
$installmentArray = $this->installmentData;

?>
<div id="pad-wrapper">
    <div class="row pagelist-header">
        <h3>Loan Detail</h3>
    </div>
    <div class="table-products">
       
        <div class="row-fluid ">
            <div class="pull-right">
                <a class="btn-flat new-product" href="<?php echo $this->url(array('module' => 'default', 'controller' => 'loan', 'action' => 'list'), null, TRUE); ?>"> Back</a>
            </div>              
        </div>
        <div class="row show-grid">
            <div class="span5"> 
                
            <div class="sub_main">
                <div class="detail_label">Name: </div>
                <div class="detail_data"><?php echo ucfirst($loan_model['ln_name']); ?></div>
            </div>


            
            <div class="sub_main">
                <div class="detail_label">Customer Name: </div>
                <div class="detail_data"><?php echo $loan_model['cus_name']; ?></div>
            </div>


            <div class="sub_main">
                <div class="detail_label">Agent Name: </div>
                <div class="detail_data"><?php echo $loan_model['ag_name']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Amount (INR): </div>
                <div class="detail_data"><?php echo $loan_model['ln_amount']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Advance Amount (INR): </div>
                <div class="detail_data"><?php echo $loan_model['ln_advance']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Start Date: </div>
                <div class="detail_data"><?php echo $loan_model['ln_startdate']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">End Date: </div>
                <div class="detail_data"><?php echo $loan_model['ln_enddate']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Guarantor Name: </div>
                <div class="detail_data"><?php echo ( $loan_model['ln_guarantor_name'] == '' ) ? '---' : $loan_model['ln_guarantor_name'];  ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Guarantor Address: </div>
                <div class="detail_data"><?php echo ( $loan_model['ln_guarantor_address'] == '' ) ? '---' : $loan_model['ln_guarantor_address']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Guarantor Mobile No.: </div>
                <div class="detail_data"><?php echo ( $loan_model['ln_guarantor_mobile'] == '' )? '---' : $loan_model['ln_guarantor_mobile']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Note: </div>
                <div class="detail_data"><?php echo ( $loan_model['ln_note'] == '' )? '---' : $loan_model['ln_note']; ?></div>
            </div>
            
            <div class="sub_main">
                <div class="detail_label">Created Date: </div>
                <div class="detail_data"><?php echo date('Y-m-d', strtotime($loan_model['ln_createddate'])); ?></div>
            </div>

            <div class="sub_main">
                <div class="detail_label">Updated Date: </div>
                <div class="detail_data"><?php echo date('Y-m-d', strtotime($loan_model['ln_updateddate'])); ?></div>
            </div>

            
            
            <div class="sub_main">
                <div class="detail_label">Status: </div>
                <div class="detail_data">
                    <?php echo ( $loan_model['ln_status'] == 1 ) ? 'Active' : 'Inactive'; ?>
                </div>
            </div>

       
            </div>
            <div class="span5"> 
                <h3>Installment</h3>
                <div class="right_link">
                    <a class="label-add" title="Add Installment" href="<?php echo $this->url(array('controller' => 'installment', 'action' => 'form', 'ln_id' => $loan_model["ln_id"]), null, true); ?>">
                        Add Installment
                    </a>
                    &nbsp;&nbsp;
                    <a class="label-add" href="<?php echo $this->url(array('module' => 'default', 'controller' => 'loan', 'action' => 'getcsv', 'ln_id' => $loan_model["ln_id"]), null, TRUE); ?>">
                      Download CSV
                    </a>
                </div>
                <table border="1" cellpadding="0" cellspacing="0">
                    <tr>
                        <th>Credit Date</th>
                        <th>Uptil Date</th>
                        <th>Amount (INR)</th>
                    </tr>
                     <?php if (count($installmentArray) > 0):
                         $totalamount="";?>
                    <?php foreach($installmentArray as $key =>$value):
                        $totalamount += $value['ins_amount'];
                        ?>
                    <tr>
                        <td><?php echo $value['ins_creditdate']?></td>
                        <td><?php echo $value['ins_uptodate']?></td>
                        <td><?php echo $value['ins_amount']?>
                            <a style="float: right" target="_blank" title="View Installment" class="view_anchr" href="<?php echo $this->url(array('controller' => 'installment', 'action' => 'view', 'ins_id' => $value["ins_id"]), null, true); ?>">
                            View
                        </a>
                        </td>
                    </tr>
                    <?php endforeach;?>
                    <tr>
                        <td colspan="2" style="text-align: right;font-weight: bold">Total Amount:</td>
                        <td><?php echo $totalamount;?></td>
                        
                    </tr>
                    <?php else:?>
                        <tr>
                            <td colspan="3" style="text-align: center">No installment yet.</td>
                        </tr>
                    <?php endif;?>
                    
                </table>
            </div>
        </div>
    </div>
</div>
